home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / cwscr.exe / MYMOU.CPP < prev    next >
Text File  |  1991-07-28  |  3KB  |  159 lines

  1. /*
  2.     Mouse module class specification.
  3.  
  4.     This is the source file that contains the actual source to the
  5.     routines used to access a mouse pointing device.
  6.  
  7.     Library : mycpp.lib
  8. */
  9.  
  10. static char MyMou_Id[] = "mymou.cpp     1.10 05/22/91";
  11. /*
  12.     Version notes :
  13.         1.00 - Original creation / release. ( 2-13-91 CW )
  14.         1.10 - Added enumeration for button specifier. ( 5-22-91 CW )
  15. */
  16.  
  17.  
  18. #include <dos.h>
  19. #include "mymou.h"
  20.  
  21. /* ------------------------------------------------------------------ */
  22. void
  23. myMouse::poll_mouse(){
  24.     union   REGS    mousreg;
  25.  
  26.     mousreg.x.ax = m1;
  27.     mousreg.x.bx = m2;
  28.     mousreg.x.cx = m3;
  29.     mousreg.x.dx = m4;
  30.     int86(0x33, &mousreg, &mousreg);        /* mouse interrupt */
  31.  
  32.     m1 = mousreg.x.ax;
  33.     m2 = mousreg.x.bx;
  34.     m3 = mousreg.x.cx;
  35.     m4 = mousreg.x.dx;
  36. };
  37.  
  38. /* .................................................................. */
  39. void
  40. myMouse::show(){
  41.     if( !status ){
  42.         m1 = 1;
  43.         poll_mouse();
  44.         status = 1;
  45.     }
  46. }
  47.  
  48. /* .................................................................. */
  49. void
  50. myMouse::hide(){
  51.     if( status ){
  52.         m1 = 2;
  53.         poll_mouse();
  54.         status = 0;
  55.     }
  56. }
  57.  
  58. /* .................................................................. */
  59. int
  60. myMouse::pressed( ButtonType button ){
  61.     m1 = 5;
  62.     m2 = (int)button;
  63.  
  64.     poll_mouse();
  65.  
  66.     button_s = m1;
  67.     count = m2;
  68.     xp_pos = m3;
  69.     yp_pos = m4;
  70.  
  71.     return( count );
  72. }
  73.  
  74. /* .................................................................. */
  75. int
  76. myMouse::released( ButtonType button ){
  77.     m1 = 6;
  78.     m2 = (int)button;
  79.  
  80.     poll_mouse();
  81.  
  82.     button_s = m1;
  83.     count = m2;
  84.     xr_pos = m3;
  85.     yr_pos = m4;
  86.  
  87.     return( count );
  88. }
  89.  
  90. /* .................................................................. */
  91. void
  92. myMouse::xlimits( int low, int high ){
  93.     m1 = 7;
  94.     m3 = low * 8;
  95.     m4 = high * 8;
  96.     poll_mouse();
  97. }
  98.  
  99. /* .................................................................. */
  100. void
  101. myMouse::ylimits( int low, int high ){
  102.     m1 = 8;
  103.     m3 = low * 8;
  104.     m4 = high * 8;
  105.     poll_mouse();
  106. }
  107.  
  108.  
  109. /* ================================================================== */
  110.  
  111.  
  112. #ifdef debug_mouse
  113.  
  114.  
  115. #include <stdio.h>
  116. #include <conio.h>
  117.  
  118. main(){
  119.     int     done = 0;
  120.     myMouse aMouse;
  121.  
  122.     aMouse.show();
  123.     while( !done ){
  124.         if( aMouse.pressed( LEFT_BUTTON )){
  125.             aMouse.hide();
  126.             printf( "pressed :  x = %d, y = %d\n",
  127.                 aMouse.xpress(), aMouse.ypress() );
  128.             aMouse.show();
  129.         }
  130.         if( aMouse.released( RIGHT_BUTTON )){
  131.             aMouse.hide();
  132.             printf( "released :  x = %d, y = %d\n",
  133.                 aMouse.xrelease(), aMouse.yrelease() );
  134.             aMouse.show();
  135.             aMouse.xlimits( 0, 79 );
  136.             aMouse.ylimits( 0, 24 );
  137.         }
  138.         if( aMouse.released( MIDDLE_BUTTON )){
  139.             aMouse.hide();
  140.             printf( "middle :  x = %d, y = %d\n",
  141.                 aMouse.xrelease(), aMouse.yrelease() );
  142.             aMouse.show();
  143.             aMouse.xlimits( 5, 20 );
  144.             aMouse.ylimits( 5, 10 );
  145.         }
  146.  
  147.         if( kbhit() ){
  148.             done = 1;
  149.             if( !getch() )     // empty the keyboard buffer.
  150.                 getch();
  151.         }
  152.     }
  153.  
  154.     return( 0 );
  155. }
  156.  
  157. #endif
  158.  
  159.